package com.sjy.project.ent.yearSta.service.impl;

import java.util.List;

import com.sjy.common.result.BaseResponse;
import com.sjy.common.utils.DateUtils;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sjy.project.ent.yearSta.mapper.EntKpiYearStaMapper;
import com.sjy.project.ent.yearSta.domain.EntAmmeter;
import com.sjy.project.ent.yearSta.domain.EntKpiYearSta;
import com.sjy.project.ent.yearSta.domain.EntLandData;
import com.sjy.project.ent.yearSta.domain.EntRentInLand;
import com.sjy.project.ent.yearSta.domain.EntRentOutLand;
import com.sjy.project.ent.yearSta.domain.EntWater;
import com.sjy.project.ent.yearSta.service.IEntAmmeterService;
import com.sjy.project.ent.yearSta.service.IEntKpiYearStaService;
import com.sjy.project.ent.yearSta.service.IEntLandDataService;
import com.sjy.project.ent.yearSta.service.IEntRentInLandService;
import com.sjy.project.ent.yearSta.service.IEntRentOutLandService;
import com.sjy.project.ent.yearSta.service.IEntWaterService;
import com.sjy.common.utils.text.Convert;

/**
 * 工业企业绩效综合评价Service业务层处理
 * 
 * @author ljb
 * @date 2022-06-05
 */
@Service
public class EntKpiYearStaServiceImpl implements IEntKpiYearStaService 
{
    @Autowired
    private EntKpiYearStaMapper entKpiYearStaMapper;
    @Autowired
    private IEntAmmeterService ammeterService;
    @Autowired
    private IEntWaterService waterService;
    @Autowired
    private IEntLandDataService landDataService;
    @Autowired
    private IEntRentInLandService rentInLandService;
    @Autowired
    private IEntRentOutLandService rentOutLandService;

    /**
     * 查询工业企业绩效综合评价
     * 
     * @param id 工业企业绩效综合评价主键
     * @return 工业企业绩效综合评价
     */
    @Override
    public EntKpiYearSta selectEntKpiYearStaById(Long id)
    {
        return entKpiYearStaMapper.selectEntKpiYearStaById(id);
    }

    /**
     * 查询统代跟年份查询详情
     * 
     * @param id 工业企业绩效综合评价主键
     * @return 工业企业绩效综合评价
     */
    public EntKpiYearSta getByCreditCodeAndYear(String creditCode,Integer dataYear) {
    	return entKpiYearStaMapper.getByCreditCodeAndYear(creditCode, dataYear);
    }
    /**
     * 查询统代跟年份查询详情包含各种list
     * 
     * @param id 工业企业绩效综合评价主键
     * @return 工业企业绩效综合评价
     */
    public EntKpiYearSta getByCreditCodeAndYearWithList(String creditCode,Integer dataYear) {
    	EntKpiYearSta entKpiYearSta = entKpiYearStaMapper.getByCreditCodeAndYear(creditCode, dataYear);
    	if(entKpiYearSta != null) {
        	//详情需要填充 电费 水费 自有产权证 出租 承租信息
    		EntAmmeter entAmmeter = new EntAmmeter();
    		entAmmeter.setKpiId(entKpiYearSta.getId());
    		entAmmeter.setDelFlag("0");
    		entKpiYearSta.setAmmeters(ammeterService.selectEntAmmeterList(entAmmeter));
    		
    		EntWater water = new EntWater();
    		water.setKpiId(entKpiYearSta.getId());
    		water.setDelFlag("0");
    		entKpiYearSta.setWaters(waterService.selectEntWaterList(water));
    		

    		EntLandData landData = new EntLandData();
    		landData.setKpiId(entKpiYearSta.getId());
    		landData.setDelFlag("0");
    		entKpiYearSta.setLandDatas(landDataService.selectEntLandDataList(landData));
    		
    		//承租土地信息
    		EntRentInLand rentInLand = new EntRentInLand();
    		rentInLand.setCreditCode(creditCode);
    		rentInLand.setDataYear(dataYear);
    		rentInLand.setDelFlag("0");
    		entKpiYearSta.setRentInLands(rentInLandService.selectEntRentInLandList(rentInLand));
    		
    		//出租土地信息
    		EntRentOutLand rentOutLand = new EntRentOutLand();
    		rentOutLand.setCreditCode(creditCode);
    		rentOutLand.setDataYear(dataYear);
    		rentOutLand.setDelFlag("0");
    		entKpiYearSta.setRentOutLands(rentOutLandService.selectEntRentOutLandList(rentOutLand));
    	}
    	return entKpiYearSta;
    }
    /**
     * 通过社会统一代码查询企业档案信息
     * @param creditCode
     * @return
     */
    public EntKpiYearSta selectEntKpiYearStaByCreditCode(String creditCode,Integer dataYear) {
    	return entKpiYearStaMapper.selectEntKpiYearStaByCreditCode(creditCode, dataYear);
    }
    /**
     * 查询工业企业绩效综合评价列表
     * 
     * @param entKpiYearSta 工业企业绩效综合评价
     * @return 工业企业绩效综合评价
     */
    @Override
    public List<EntKpiYearSta> selectEntKpiYearStaList(EntKpiYearSta entKpiYearSta)
    {
        return entKpiYearStaMapper.selectEntKpiYearStaList(entKpiYearSta);
    }

    /**
     * 新增工业企业绩效综合评价
     * 
     * @param entKpiYearSta 工业企业绩效综合评价
     * @return 结果
     */
    @Override
    public int insertEntKpiYearSta(EntKpiYearSta entKpiYearSta)
    {
        entKpiYearSta.setCreateTime(DateUtils.getNowDate());
        return entKpiYearStaMapper.insertEntKpiYearSta(entKpiYearSta);
    }

    /**
     * 修改工业企业绩效综合评价
     * 
     * @param entKpiYearSta 工业企业绩效综合评价
     * @return 结果
     */
    @Override
    public int updateEntKpiYearSta(EntKpiYearSta entKpiYearSta)
    {
        entKpiYearSta.setUpdateTime(DateUtils.getNowDate());
        return entKpiYearStaMapper.updateEntKpiYearSta(entKpiYearSta);
    }

    /**
     * 批量删除工业企业绩效综合评价
     * 
     * @param ids 需要删除的工业企业绩效综合评价主键
     * @return 结果
     */
    @Override
    public int deleteEntKpiYearStaByIds(String ids)
    {
        return entKpiYearStaMapper.deleteEntKpiYearStaByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除工业企业绩效综合评价信息
     * 
     * @param id 工业企业绩效综合评价主键
     * @return 结果
     */
    @Override
    public int deleteEntKpiYearStaById(Long id)
    {
        return entKpiYearStaMapper.deleteEntKpiYearStaById(id);
    }
}
